var app = getApp(), WxParse = require("../wxParse/wxParse.js");
Page({
    data: {
        shouMore: !0,
        moreUsers: !0,
        moreUser: !0,
        sc: !0,
        fwxy: !0,
        choose: !1,
        widths: 300,
        heigths: 400,
        haibao: !0,
        shengchengewm: !0,
        loading: !0,
        getUseInfo: !0,
        is_hy: 0,
        uid: "",
        f_id: "",
        deposit: "",
        u_id: "",
        close: !1,
        formId:'',
        list: [],
        startArr:5,
        is_authority:true,
        jztype:'qy', //兼职类型
        jzfz:100,//商户要求的分值
        jzshow:false,
        jzshowtitle:false,
        issueMoney:0,
        governmentList:''
    },
    lookck: function() {
        var t = this.data.choose;
        this.setData({
            fwxy: !1,
            choose: !t
        });
    },
    onLoad: function(a) {
        var e = this, t = a.f_id;
        if ("" == a.fx_uid && null == a.fx_uid || (e.setData({
            fx_uid: a.fx_uid,
            f_id: t
        }), app.util.request({
            url: "entry/wxapp/base",
            success: function(t) {
                e.setData({
                    base: t.data.data
                }), 1 == t.data.data.is_fx && e.getUserfenxiao(a.fx_uid);
            }
        })), e.getUsers(), e.getJianzhixq(t), app.util.request({
            url: "entry/wxapp/Jianzhi_liulan",
            data: {
                f_id: t
            }
        }), wx.getSystemInfo({
            success: function(t) {
                e.setData({
                    widths: .8 * t.windowWidth,
                    heigths: .8 * t.windowHeight
                });
            }
        }), "" != wx.getStorageSync("useInfo")) {
            var i = !1;
            e.setData({
                getUseInfo: i
            });
        } else {
            i = !0;
            e.setData({
                getUseInfo: i
            });
        };
        e.governmentDetails(t);
    },
    governmentDetails:function(typeid){
        var self = this;
        app.util.request({
            url: "entry/wxapp/Release",
            data: {
                   id:typeid,
                   openid:wx.getStorageSync("openid")
                 },
            success: function(a) {
                console.log("返回成功"+JSON.stringify(a));
                WxParse.wxParse("article", "html", a.data.data.content, self, 5);
                self.setData({
                    governmentList: a.data.data
                });
            }
        });
    },
    goSmallprogrom:function(n){
        var self = this,g_appid=n.currentTarget.dataset.apid,g_path=n.currentTarget.dataset.apth;
        wx.navigateToMiniProgram({
        appId: g_appid,//小程序appid
        path: g_path,//跳转关联小程序app.json配置里面的地址
        extraData: {//需要传递给目标小程序的数据，目标小程序可在 App.onLaunch()，App.onShow() 中获取到这份数据。
          foo: 'bar'
         },
   //**重点**要打开的小程序版本，有效值 develop（开发版），trial（体验版），release（正式版） 
       envVersion: 'release',
       success(res) {
         // 打开成功
        console.log("打开成功");
        }
       })
    },
    getUserfenxiao: function(t) {
        app.util.request({
            url: "entry/wxapp/Addfenxiao",
            data: {
                openid: wx.getStorageSync("openid"),
                fx_uid: t
            }
        });
    },
    onGotUserInfo: function(t) {
        console.log(t), "getUserInfo:ok" == t.detail.errMsg ? (wx.setStorageSync("useInfo", "true"), 
        this.getGetUid(t.detail.userInfo), this.setData({
            getUseInfo: !1
        })) : this.setData({
            getUseInfo: !0
        });
    },
    getGetUid: function(t) {
        var e = this;
        wx.login({
            success: function(a) {
                a.code && app.util.request({
                    url: "entry/wxapp/GetUid",
                    data: {
                        code: a.code
                    },
                    success: function(s) {
                        s.data.errno || (wx.setStorageSync("openid", s.data.data.openid), console.log(s.data.data.openid), 
                        console.log(t), app.util.request({
                            url: "entry/wxapp/TyMember",
                            data: {
                                u_name: t.nickName,
                                u_thumb: t.avatarUrl,
                                u_sex: t.gender,
                                openid: s.data.data.openid
                            }
                        })), wx.getLocation({
                            type: "wgs84",
                            success: function(t) {
                                var a = t.longitude, e = t.latitude, i = t.speed, n = t.accuracy;
                                app.util.request({
                                    url: "entry/wxapp/Weizhi",
                                    cachetime: "30",
                                    data: {
                                        latitude: e,
                                        longitude: a,
                                        openid: s.data.data.openid,
                                        speed: i,
                                        accuracy: n
                                    }
                                });
                            }
                        }), null != e.data.fx_popenid && "" != e.data.fx_popenid && "undefined" != e.data.fx_popenid && 1 == e.data.base.is_fx && app.util.request({
                            url: "entry/wxapp/Addfenxiao",
                            data: {
                                fx_uid: e.data.fx_uid,
                                openid: s.data.data.openid,
                                fx_name: t.nickName,
                                fx_thumb: t.avatarUrl
                            }
                        }), app.util.request({
                            url: "entry/wxapp/User",
                            data: {
                                openid: s.data.data.openid
                            },
                            success: function(t) {
                                e.setData({
                                    uid: a.data.data.u_id,
                                    is_hy: t.data.data.u_hy
                                });
                            }
                        });
                    }
                });
            }
        });
    },
    getUsers: function() {
        var a = this;
        app.util.request({
            url: "entry/wxapp/User",
            data: {
                openid: wx.getStorageSync("openid")
            },
            success: function(t) {
                console.log(t.data.data.u_hy), a.setData({
                    is_hy: t.data.data.u_hy,
                    u_id: t.data.data.u_id
                }), 0 == t.data.data.u_status && a.setData({
                    close: !0
                });
            }
        });
    },
    backindex: function(t) {
        this.getform(t.detail.formId), wx.reLaunch({
            url: "../index/index"
        });
    },
    disscroll: function() {},
    closemodal: function(t) {
        this.setData({
            haibao: !0,
            shengchengewm: !0,
            jzshow:false,
        });
        this.getform(t.detail.formId);
    },
    haibaosc: function(t) {
        this.getform(t.detail.formId), this.setData({
            haibao: !1
        });
    },
    baocunhaibao: function(t) {
        var a = this;
        a.getform(t.detail.formId), wx.showModal({
            title: "提示",
            content: "是否保存该海报",
            success: function(t) {
                t.confirm && wx.canvasToTempFilePath({
                    canvasId: "mycanvas",
                    success: function(t) {
                        console.log(t.tempFilePath);
                        t.tempFilePath;
                        wx.saveImageToPhotosAlbum({
                            filePath: t.tempFilePath,
                            success: function(t) {
                                wx.showToast({
                                    title: "保存成功"
                                }), a.setData({
                                    haibao: !0
                                });
                            }
                        });
                    }
                });
            }
        });
    },
    ewmshare: function(t) {
        this.setData({
            haibao: !1,
            shengchengewm: !1
        }), this.getform(t.detail.formId);
    },
    moreUserShow: function() {
        this.setData({
            shouMore: !1,
            moreUser: !1,
            moreUsers: !0
        });
    },
    getJianzhixq: function(t) {
        var g = this;
        app.util.request({
            url: "entry/wxapp/Jianzhi_infoxq",
            data: {
                openid: wx.getStorageSync("openid"),
                f_id: t
            },
            success: function(a) {
                if (console.log(a.data.data), null == a) loading = !0; else {
                    7 < a.data.data.bmz.length && (g.setData({
                        moreUsers: !1,
                        bmz_first: a.data.data.bmz.slice(0, 7),
                        bmz_more: a.data.data.bmz.slice(7)
                    }), console.log(g.data.bmz_first)), g.setData({
                        thumb: a.data.data.thumb,
                        jianzhi_infoxq: a.data.data,
                        loading: !1
                    });
                    var t = a.data.data.f_id;
                    app.util.request({
                        url: "entry/wxapp/Userbaiming",
                        data: {
                            openid: wx.getStorageSync("openid"),
                            f_id: t
                        },
                        success: function(t) {
                            console.log(t), g.setData({
                                deposit: t.data.data.money
                            });
                        }
                    }), console.log(a.data.data.erweima), wx.getImageInfo({
                        src: a.data.data.erweima,
                        success: function(t) {
                            var h = t.path;
                            wx.getImageInfo({
                                src: a.data.data.haibao,
                                success: function(f) {
                                    wx.getImageInfo({
                                        src: a.data.data.u_thumb,
                                        success: function(t) {
                                            var a = f.path, e = wx.createCanvasContext("mycanvas"), i = g.data.widths, n = g.data.heigths, s = g.data.jianzhi_infoxq.gongsi, o = g.data.jianzhi_infoxq.f_jianzhistyle, d = g.data.jianzhi_infoxq.f_jiesuan, r = "薪资：" + g.data.jianzhi_infoxq.f_xinzi + g.data.jianzhi_infoxq.f_danwei, u = g.data.jianzhi_infoxq.f_renshu, c = g.data.jianzhi_infoxq.f_name, l = o + "|" + d + "|" + u + "人";
                                            e.rect(0, 0, 1 * i, 1 * n), e.drawImage(a, 0, 0, 1 * i, 1 * n), e.drawImage(t.path, .38 * i, .18 * n, .24 * i, .24 * i), 
                                            e.setFontSize(.08 * i), e.setFillStyle("#000"), e.fillText(s, (i - e.measureText(s).width) / 2, .42 * n), 
                                            e.setFontSize(.05 * i), e.setFillStyle("#000"), e.fillText(c, .16 * i, .56 * n), 
                                            e.setFontSize(.04 * i), e.setFillStyle("red"), e.fillText(r, .6 * i, .63 * n), e.setFontSize(.04 * i), 
                                            e.setFillStyle("#000"), e.fillText(l, .16 * i, .63 * n), e.drawImage(h, .34 * i, .7 * n, .32 * i, .32 * i), 
                                            e.draw();
                                        }
                                    });
                                }
                            });
                        }
                    }), "true" == a.data.data.shoucang && g.setData({
                        sc: !1
                    });
                }
            }
        });
    },
    sendClick: function(a) {
        const self = this;
        console.log(JSON.stringify(self.data.jianzhi_infoxq));
        app.util.request({
            url: "entry/wxapp/Jianzhi_type_yajin",
            data: {
                type: self.data.jianzhi_infoxq.f_jianzhitype
            },
             success: function(t) {
                self.setData({
                    issueMoney:t.data.data
                });
            }
        })
         self.setData({
            jzshow:false,
          });
        self.getform(a.detail.formId), app.util.request({
            url: "entry/wxapp/User",
            data: {
                openid: wx.getStorageSync("openid")
            },
            success: function(t) {
                wx.getStorageSync("openid") == self.data.jianzhi_infoxq.f_openid ? wx.showToast({
                    title: "您是发布者",
                    image: "/hyb_jianzhi/images/errors.png"
                }) : self.data.jianzhi_infoxq.f_renshu == self.data.jianzhi_infoxq.luyong ? wx.showToast({
                    title: "录用已满",
                    image: "/hyb_jianzhi/images/errors.png"
                }) : null == t.data.data.u_bname ? wx.showModal({
                    title: "提示",
                    content: "请先完善信息",
                    success: function(t) {
                        t.confirm && wx.navigateTo({
                            url: "/hyb_jianzhi/edit/edit"
                        });
                    }
                }) : "待审核" == t.data.data.u_typs ? wx.showToast({
                    title: "请等待审核",
                    image: "/hyb_jianzhi/images/errors.png"
                }) : "不限" != self.data.jianzhi_infoxq.f_sex && t.data.data.u_sex != self.data.jianzhi_infoxq.f_sex ? wx.showToast({
                    title: "不符合需求",
                    image: "/hyb_jianzhi/images/errors.png"
                }) : app.util.request({
                    url: "entry/wxapp/Userbaiming",
                    data: {
                        openid: wx.getStorageSync("openid"),
                        b_id: self.data.jianzhi_infoxq.f_id
                    },
                    success: function(t) {
                       if ("false" == t.data.data.baoming) {
                            wx.navigateTo({
                                        url: "/hyb_jianzhi/send/send?f_id=" + self.data.jianzhi_infoxq.f_id+'&issueMoney='+self.data.issueMoney+'&jzType='+self.data.jianzhi_infoxq.f_jianzhitype
                                    }) 
                        } else "true" == t.data.data.baoming && wx.showToast({
                            title: "您已报名",
                            image: "/hyb_jianzhi/images/errors.png"
                        });
                    }
                });
            }
        });
    },
    sendClickJudge:function(a){
        const self = this,g_id=a.currentTarget.dataset.g_id,status=a.currentTarget.dataset.g_status;
         if(status == 0){
             wx.navigateTo({
                url: '/hyb_jianzhi/applyagent/applyagent?g_id='+ g_id
             })
         }else{
             wx.showToast({
                    title: "您已申请过！",
                    image: "/hyb_jianzhi/images/errors.png"
              })
         }
         
    },
      sendClickAgent: function(a) {
        const self  = this;
        console.log(JSON.stringify(self.data.jianzhi_infoxq));
        self.setData({
            jzshow:false,
        });
        this.getform(a.detail.formId), app.util.request({
            url: "entry/wxapp/User",
            data: {
                openid: wx.getStorageSync("openid")
            },
            success: function(t) {
                null == t.data.data.u_bname ? wx.showModal({
                    title: "提示",
                    content: "请先完善信息",
                    success: function(t) {
                        t.confirm && wx.navigateTo({
                            url: "/hyb_jianzhi/edit/edit"
                        });
                    }
                }): app.util.request({
                    url: "entry/wxapp/Userbaiming",
                    data: {
                        openid: wx.getStorageSync("openid"),
                        f_id: self.data.jianzhi_infoxq.f_id
                    },
                    success: function(t) {
                        // 跳转到代理兼职详情页
                        "true" == t.data.data.baoming && wx.showToast({
                            title: "您已报名",
                            image: "/hyb_jianzhi/images/errors.png"
                        });
                    }
                });
            }
        });
    },
    hdlGoHome:function(){
         wx.navigateTo({
                url: '/hyb_jianzhi/index/index'
             })
    },
    callPhone: function(t) {
        var a = t.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    seeLoaction: function(t) {
        console.log(t), this.getform(t.detail.formId), wx.openLocation({
            latitude: parseFloat(t.detail.target.dataset.latitude),
            longitude: parseFloat(t.detail.target.dataset.longitude),
            address: t.detail.target.dataset.address,
            scale: 22
        });
    },
    getform: function(t) {
        console.log(t), app.util.request({
            url: "entry/wxapp/Formid",
            data: {
                openid: wx.getStorageSync("openid"),
                formid: t
            },
            success: function(t) {
            }
        });
    },
    timeJobMore: function() {
        wx.reLaunch({
            url: "/hyb_jianzhi/time_job_more/time_job_more"
        });
    },
    onReady: function() {},
    collect: function(t) {
        this.getform(t.detail.formId), this.data.sc ? (wx.showToast({
            title: "已收藏",
            image: "../images/success_02.png"
        }), app.util.request({
            url: "entry/wxapp/Jianzhi_shoucang",
            data: {
                openid: wx.getStorageSync("openid"),
                f_id: t.currentTarget.dataset.f_id,
                typs: "shou"
            }
        })) : (wx.showToast({
            title: "已取消收藏",
            image: "../images/errors.png"
        }), app.util.request({
            url: "entry/wxapp/Jianzhi_shoucang",
            data: {
                openid: wx.getStorageSync("openid"),
                f_id: t.currentTarget.dataset.f_id,
                typs: "quxiao"
            }
        })), this.setData({
            sc: !this.data.sc
        });
    },
    onShow: function() {
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var a = this,infotie=a.data.jianzhi_infoxq.f_name+"("+"还差"+(a.data.jianzhi_infoxq.f_renshu-a.data.jianzhi_infoxq.baomingnum)+"人"+")";
        if(a.data.jianzhi_infoxq.f_renshu-a.data.jianzhi_infoxq.baomingnum <= 0){
           infotie = a.data.jianzhi_infoxq.f_name
        };
        return {
            title: infotie,
            path: "/hyb_jianzhi/job_detail/job_detail?j_id=" + a.data.f_id + "&fx_uid=" + a.data.uid,
            success: function(t) {
                a.setData({
                    haibao: !0
                });
            },
            fail: function(t) {}
        };
    }
});